package core.proto.vis.action;

import java.util.Iterator;

import prefuse.Visualization;
import prefuse.action.GroupAction;
import prefuse.data.tuple.TupleSet;
import prefuse.visual.EdgeItem;
import prefuse.visual.NodeItem;

public class NodeOrderAction extends GroupAction
{
    public NodeOrderAction( String graphGroup ) {
        super( graphGroup );
    }

    @Override
    public void run( double frac_ ) {
        TupleSet focus = m_vis.getGroup( Visualization.FOCUS_ITEMS );
        if( focus == null || focus.getTupleCount() == 0 )
            return;

        EdgeItem e = null;
        Object o = null;
        @SuppressWarnings("rawtypes")
        Iterator tuples = focus.tuples();
        while( tuples.hasNext() ) {
            o = tuples.next();
            // if o is not a node or it's not part of the graph
            if( !(o instanceof EdgeItem) ) {
                return;
            }
            e = (EdgeItem) o;
            NodeItem source = (NodeItem) e.getSourceNode();
            NodeItem target = (NodeItem) e.getTargetNode();
            source.setHighlighted( true );
            target.setHighlighted( true );
        }
    }
}
